<template>
  <div>
    <el-dialog title="修改项" :visible.sync="dialogVisible" @close="close">
      <el-form :model="formData" :rules="rules" ref="form" label-width="120px">
        <el-form-item label="名称" prop="name" label-width="120px">
          <el-input v-model="formData.name"></el-input>
        </el-form-item>
        <!-- <el-form-item label="分类">
          <el-checkbox-group v-model="formData.cats">
            <el-checkbox label="车辆信息" name="1"></el-checkbox>
            <el-checkbox label="单位信息" name="2"></el-checkbox>
            <el-checkbox label="司机信息" name="3"></el-checkbox>
            <el-checkbox label="申请用车" name="4"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>-->
      </el-form>
      <div slot="footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { changeBaseTypeById } from "@/api/dictionary";
export default {
  // watch: {
  //   ["formData.cats"]() {
  //     console.log(this.formData.cats);
  //   }
  // },
  data() {
    return {
      formData: {},
      dialogVisible: false,
      rules: {
        name: [{ required: true, message: "请输入", trigger: "blur" }],
        cats: [{ required: true, message: "请选择", trigger: "blur" }]
      }
    };
  },
  methods: {
    close() {
      this.dialogVisible = false;
    },
    show(data) {
      this.formData = JSON.parse(JSON.stringify(data));
      this.formData.baseTypeId = this.formData.id;
      this.dialogVisible = true;
    },
    save() {
      this.$refs["form"].validate(async valid => {
        if (valid) {
          let r = await changeBaseTypeById(this.formData);
          if (r && r.error == 0) {
            this.$refs["form"].resetFields();
            this.$emit("finish");
            this.close();
          } else {
            this.$message({
              message: "出错了",
              type: "error"
            });
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>
